package main

import "fmt"

func main() {
	fmt.Println("2. 变量和常量")

	// 变量声明方式1: var 变量名 类型
	var name string = "Go"
	var age int = 10
	fmt.Printf("变量声明方式1: name=%s, age=%d\n", name, age)

	// 变量声明方式2: var 变量名 类型 (默认零值)
	var city string
	var score int
	fmt.Printf("变量声明方式2(零值): city=%s, score=%d\n", city, score)

	// 变量声明方式3: var 变量名 = 值 (类型推导)
	var language = "Golang"
	var year = 2009
	fmt.Printf("变量声明方式3(类型推导): language=%s, year=%d\n", language, year)

	// 变量声明方式4: 变量名 := 值 (短变量声明，最常用)
	version := "1.25"
	company := "Google"
	fmt.Printf("变量声明方式4(短变量声明): version=%s, company=%s\n", version, company)

	// 声明多个变量
	var (
		firstName = "Go"
		lastName  = "Language"
		website   = "https://golang.org"
	)
	fmt.Printf("多变量声明: firstName=%s, lastName=%s, website=%s\n", firstName, lastName, website)

	// 常量声明
	const pi = 3.14159
	const appName = "Go学习"
	fmt.Printf("常量: pi=%f, appName=%s\n", pi, appName)

	// 常量声明块
	const (
		StatusOK       = 200
		StatusNotFound = 404
		StatusError    = 500
	)
	fmt.Printf("状态码常量: OK=%d, NotFound=%d, Error=%d\n", StatusOK, StatusNotFound, StatusError)
}
